package com.security.client;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FilePermission;
import java.io.IOException;
import java.io.InputStream;
import java.security.AccessController;
import java.security.Permission;
import java.security.PrivilegedAction;

/**
 * Client0  Failed
 *
 * @author Lizhong
 * @date 2019/4/23
 */

public class Client0 {
    public void doCheck() {

        AccessController.doPrivileged(new PrivilegedAction() {
            public Object run() {
                print00();
                return null;
            }
        });
    }

    private void check() {
        Permission perm = new FilePermission("C:\\Users\\li\\Desktop\\1.txt", "read");
        AccessController.checkPermission(perm);
        System.out.println(" TestService has permission ");
    }

    public static void main(String[] args) {
        // SecurityManager s = new SecurityManager();

        // System.setSecurityManager(s);
        Client0 client12 = new Client0();

        // client12.check();
        // client12.doCheck();
        Client0.print00();
    }

    public static void print00() {
        File file = new File("C:\\Users\\li\\Desktop\\1.txt");
        try {
            InputStream fileInputStream = new FileInputStream(file);


            int available = fileInputStream.available();
            byte[] bytes = new byte[available];
            fileInputStream.read(bytes);
            System.out.println(new String(bytes));


        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();

        }
    }

}